/**
 * 新增年度考核
 * @author 孙汉斌
 */
package com.zjht.gmcc.servlet.ass;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.action.AssessUtil;
import com.zjht.gmcc.bean.util.MyConstant;
import com.zjht.gmcc.bean.util.MyFormat;
import com.zjht.gmcc.bean.util.MyJDBC;

public class AddYearAss extends BaseServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected boolean process(HttpServletRequest request, HttpServletResponse response, HttpSession session, PrintWriter out, MyJDBC myJDBC,
			String menu) throws Exception {

		int count = MyFormat.formatInt(request.getParameter("count"));
		String s_assYear = request.getParameter("assYear");
		PreparedStatement ps = null;
		int flag = 0;
		StringBuilder sql = new StringBuilder();
		sql.append("INSERT INTO Assess(assessid,providerid,assessdate,score,assesstype)VALUES(SEQ_ASSESS_ID.NEXTVAL,?,?,?,'0')");
		ps = myJDBC.prepareStatement(sql);
		String s_providerid = "";
		String s_score = "";
		String s_score_paraid="";
		for (int i = 0; i < count; i++) {
			s_providerid = request.getParameter("providerid" + i);
			if (MyFormat.isStrNull(s_providerid)) {
				alertNullParameter(out);
				return false;
			}
			ps.setString(1, s_providerid);
			ps.setString(2, s_assYear);
			s_score = request.getParameter("score" + i);
			s_score_paraid=AssessUtil.getParaID(s_score, MyConstant.PARA_SCORE);
			ps.setString(3, s_score_paraid);
			flag = ps.executeUpdate();
			if (flag == 0) {
				break;
			}
		}
		ps.close();
		ps = null;

		String tip = "新增年度考核";
		if (flag == 1) {
			alert(out, tip + "成功", "/ass/ass.jsp");
		} else {
			errAlert(request, out, menu, tip + "失败");
		}
		return flag == 1;
	}
}
